From f699802b837d7d9fcf150ff2bf00cd3c5475c87a Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 9 Nov 2023 17:18:46 +0100 Subject: refactor(components): rewrite CommentsList component * use ApprovedCommentProps to make CommentData type * add the author name of the parent on reply form heading * add tests --- src/pages/article/[slug].tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/pages/article/[slug].tsx') diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx index 449af8d..d35541a 100644 --- a/src/pages/article/[slug].tsx +++ b/src/pages/article/[slug].tsx @@ -17,6 +17,7 @@ import { Spinner, type MetaItemData, Time, + type CommentData, } from '../../components'; import { getAllArticlesSlugs, @@ -64,6 +65,19 @@ const ArticlePage: NextPageWithLayout = ({ contentId: article?.id, fallback: comments, }); + + const getComments = (data?: SingleComment[]) => + data?.map((comment): CommentData => { + return { + author: comment.meta.author, + content: comment.content, + id: comment.id, + isApproved: comment.approved, + publicationDate: comment.meta.date, + replies: getComments(comment.replies), + }; + }); + const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({ title: article?.title ?? '', url: `${ROUTES.ARTICLE}/${slug}`, @@ -313,7 +327,7 @@ const ArticlePage: NextPageWithLayout = ({ bodyClassName={styles.body} breadcrumb={breadcrumbItems} breadcrumbSchema={breadcrumbSchema} - comments={commentsData} + comments={getComments(commentsData)} footerMeta={footerMeta} headerMeta={filteredHeaderMeta} id={id as number} -- cgit v1.2.3